package action;

import interceptor.BoardDaoAware;
import util.BoardDAO;
import util.BoardVO;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;


/*struts.xml 에서 값을 가지고 WritAction class 이동했다
*/
public class WriteAction extends ActionSupport implements Preparable, ModelDriven, BoardDaoAware {
	private BoardVO vo;
	private BoardDAO dao;
	
	public void setBoardDao(BoardDAO dao){
		System.out.println("검사1");
		this.dao = dao;
		
	}
	
	public BoardDAO getDao() {
		System.out.println("검사2");
		return dao;
	}

	public void setVo(BoardVO vo) {
		System.out.println("검사3");
		this.vo = vo;
	}

	public BoardVO getVo() {
		System.out.println("검사4");
		return vo;
	}

	public void setDao(BoardDAO dao) {
		System.out.println("검사5");
		this.dao = dao;
	}

	public void prepare() throws Exception {
		System.out.println("검사6");
		vo = new BoardVO();
	}
	
	public Object getModel(){
		System.out.println("검사7");
		return vo;
	}
	
	public void validate(){
		
		System.out.println("검사8");
		if (vo == null || vo.getWriter() == null || vo.getWriter().trim().equals("")){
			this.addFieldError("writerEmptyError", "�ۼ��ڸ� �Է��ϼ���.");
			
		}
	
		else if (vo == null || vo.getPasswd() == null || vo.getPasswd().trim().equals("")){
			this.addFieldError("passwdEmptyError", "�н����带 �Է��ϼ���.");
			System.out.println("검사12");
		}
		
		else if (vo == null || vo.getTitle() == null || vo.getTitle().trim().equals("")){
			this.addFieldError("passwdEmptyError", "������ �Է��ϼ���.");
			System.out.println("검사13");
		}
		
		else if (vo == null || vo.getContent() == null || vo.getContent().trim().equals("")){
			this.addFieldError("contentEmptyError", "������ �Է��ϼ���.");
			System.out.println("검사14");
		}
	}
	
	public String execute() throws Exception {
		System.out.println("검사9");
		System.out.println("vo="+vo);
		dao.Write(vo);
		return SUCCESS;
	}
}
